<template>
  <keep-alive>
    <router-view v-if="route.meta.keepAlive"></router-view>
  </keep-alive>
  <router-view v-if="!route.meta.keepAlive"></router-view>
</template>
<script setup lang="ts">
import { onMounted, onBeforeMount, watch } from 'vue'
import { getUser } from '/@/util/auth'
import { useStore } from '/@/store'
import { getUserInfo } from '/@/util/business-util'
import { useRoute } from 'vue-router'

const { commit, dispatch, state } = useStore()

onBeforeMount(() => {
  const ctr_user = JSON.parse(getUser())
  commit('setUser', ctr_user)
})

onMounted(() => getUserInfo(commit, state, state.user.userId, true))
const route = useRoute()

watch(
  () => state.userInfo?.tenantId,
  (val) => {
    if (!val) return
    dispatch('getTenant')
  },
  { immediate: true }
)
</script>

<style lang="less" scoped></style>
